<?php
namespace Home\Controller;
class BaojiaController extends LoginController{
	function index(){
        $this->getip();
        $this->display();
	}
	function add(){
		 if (!IS_POST) {
           	 $this->ajaxReturn(['status' => 0, 'msg' => '非法请求']);
		}

		$baojia_model            = M("Baojia");
		$_POST["addtime"] = time();
		$_POST["ip"]      = get_client_ip();

		$rules = [
	//            ['name', 'require', '请输入您的姓名！'],
		    ['huxing', 'require', '请选择您的房屋户型！'],
		    ['city', 'require', '请选择您的所在城市！'],
		    ['mobile', '/^\d{11}$/', '请输入正确的手机号！', 1, 'regex', 3],
		    ['area', 'require', '请输入您的房屋面积！'],
		];
		if (!$baojia_model->validate($rules)->create($_POST)) {
		    $this->ajaxReturn(['status' => 0, 'msg' => $baojia_model->getError()]);
		};

		if (!$baojia_model->add()) {
		    $this->ajaxReturn(['status' => 0, 'msg' => '添加失败，请重新填写！']);
		}

		$this->ajaxReturn(['status' => 1, 'msg' => '添加成功']);
	}
}
